<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <h1>用户列表</h1>
    <form action="users" method="post">
    <input type="hidden" name="pageNo">
    用户名<input name="userName" value="${userName}">
    角色
<!--     <select name="userRole"> -->
<!--     	<option value="">请选择</option> -->
    	
<!--     	<option <c:if test="${userRole=='1'}">selected="selected"</c:if> value="1">系统管理员</option> -->
<!--     	<option <c:if test="${userRole=='2'}">selected="selected"</c:if> value="2">经理</option> -->
<!--     	<option <c:if test="${userRole=='3'}">selected="selected"</c:if> value="3">普通员工</option> -->
<!--     </select> -->

    <input type="checkbox" <c:if test="${userRoles.contains('1')}">checked="checked"</c:if> name="userRoles" value="1">管理员
    <input type="checkbox" <c:if test="${userRoles.contains('2')}">checked="checked"</c:if> name="userRoles" value="2">经理
    <input type="checkbox" <c:if test="${userRoles.contains('3')}">checked="checked"</c:if> name="userRoles" value="3">用户
    <input type="radio" name="findBy" value="findByUser" <c:if test="${findBy=='findByUser'}">checked="checked"</c:if>>findByUser
    <input type="radio" name="findBy" value="findAll" <c:if test="${findBy=='findAll'}">checked="checked"</c:if>>findAll
    <button type="submit">查询</button>
    <table>
    	<tr style="background-color: grey;">
    		<td>id</td>
    		<td>username</td>
    		<td>角色ID</td>
    		<td>userCode</td>
    		<td>角色信息</td>
    		<td>地址信息</td>
    	</tr>
    	<c:forEach var="user" items="${pageBean.dataList}">
    	<tr>
    		<td>${user.id}</td>
    		<td>${user.userName }</td>
    		<td>${user.userRole }--${user.userRoleName}</td>
    		<td>${user.userCode }</td>
    		<td>${user.role.id}--${user.role.roleName}--${user.role.roleCode}</td>
    		<td>
    			<c:forEach var="addr" items="${user.addresses}">
    				${addr.id} --- ${addr.contact} -- ${addr.addressDesc}
    			</c:forEach>
    		</td>
    	</tr>
    	</c:forEach>
    </table>
    <div>
    	<div>
    		${pageBean.pageNo}/${pageBean.totalPages}页，共${pageBean.total}条
    	</div>
    	<a href="javascript:doPage(1)">首页</a>
    	<a href="javascript:doPage(${pageBean.pageNo-1})">上页</a>
    	<a href="javascript:doPage(${pageBean.pageNo+1})">下页</a>
    	<a href="javascript:doPage(${pageBean.totalPages})">尾页</a>
    	<input type="text" size="2" maxlength="2" name="pageSize" value="${pageBean.pageSize}">
    </div>
    </form>
  </body>
  <script>
  	function doPage(pageNo) {
  		document.forms[0].pageNo.value = pageNo;
  		document.forms[0].submit();
  	}
  </script>
</html>
